package cn.animal; 

import java.util.ArrayList; 

import java.util.List; 

public class AnimalLoc implements DataAccess{ 

public String getLocName() { 

return locName; 

} 

public void setLocName(String locName) { 

this.locName = locName; 

} 

private String locName; 

private List<Animal> locAnimalList; 

public AnimalLoc(){ 

this.locAnimalList = new ArrayList<Animal>(); 

} 

public AnimalLoc(List<Animal> Animalloc){ 

this.locAnimalList = Animalloc; 

} 

@Override 

public boolean addAnimal(Animal animal) { 

return this.locAnimalList.add(animal); 

} 

@Override 

public boolean deleteAnimal(Animal animal) { 

return this.locAnimalList.remove(animal); 

} 

@Override 

public boolean deleteAnimal(String animalName) { 

return this.locAnimalList.remove(findAnimal(animalName)); 

} 

@Override 

public boolean updateAnimal(Animal oldAnimal, Animal newAnimal) { 

boolean successedRemoved = this.locAnimalList.remove(oldAnimal); 

boolean successAdded = this.locAnimalList.add(newAnimal); 

return (successAdded && successedRemoved); 

} 

@Override 

public Animal findAnimal(String animalName) { 

Animal foundAnimal = null; 

for(Animal animal : this.locAnimalList){ 

if(animal.getAnimalName().equals(animalName)){ 

foundAnimal = animal; 

} 

} 

return foundAnimal; 

} 

public String displayAllAnimals(){ 

String dis = ""; 

for(Animal animal : this.locAnimalList){ 

dis += animal.getAnimalName(); 

} 

return dis; 

} 

}